import com.zgr.hibernate.entity.User;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate5.HibernateTemplate;

import java.util.List;

public class UserMapperCase {

    public AbstractApplicationContext ac;
    public HibernateTemplate ht;
    /**
     * 查询整表
     */
    @Test
    public void test1(){
        // 3.执行操作
        List<User> list = ht.loadAll(User.class);
        for (User user : list) {
            System.out.println(user);
        }
    }

    @Before
    public void doBefore(){
        // 1.获取Spring容器
        ac = new ClassPathXmlApplicationContext("spring-hibernate.xml");
        // 2.根据id获取bean对象
        ht = (HibernateTemplate) ac.getBean("hibernateTemplate");
    }

    @After
    public void doAfter(){
        ac.close();
    }
}
